<?php
/**
 * 显示user页面
 * @param  string
 * @return [type]
 */
function user_show_login() {
	$action = isset($_POST['action']) ? trim($_POST['action']) : '';
	if (!empty($action) && $action == 'login') {
		user_check_login();
	} else {
		include APP_VIEW . 'user/login.php';
	}

}

function user_check_login() {
	$action = isset($_POST['action']) ? trim($_POST['action']) : '';
	if (!empty($action) && $action == 'login') {

		$account = isset($_POST['account']) ? trim($_POST['account']) : '';
		$password = isset($_POST['password']) ? intval($_POST['password']) : 0;
		require_once APP_PATH . DIRECTORY_SEPARATOR . 'user/model.php';
		$ret = user_model_login($account, $password);
		$login_data = array(
			'code' => 0,
			'msg' => '',
		);
		if ($ret) {
			//存放到session中去
			$_SESSION['is_login'] = true;
			$_SESSION['uid'] = $ret['id'];
			$_SESSION['nickname'] = $ret['nickname'];
			$_SESSION['username'] = $ret['username'];
			$_SESSION['account'] = $ret['username'];
			$login_data['code'] = 1;
			$login_data['msg'] = '登录成功';

		} else {

			$login_data['code'] = 0;
			$login_data['msg'] = '账号或密码错误';
		}
		echo json_encode($login_data);
	}
}
/**
 * 调用入口
 */
user_show_login();